package tools;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.PrintWriter;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PdfImageFactory extends HttpServlet{
	
	public void init() throws ServletException
    {
        super.init();
    }
	
	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setHeader("Pragma","No-cache");
        response.setHeader("Cache-Control","no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/jpeg");
        
		String id = (String)request.getParameter("id");
		System.out.println(id);
		Integer index = Integer.parseInt(id);
		ChangePdf change = new ChangePdf("E:/123.pdf");
		BufferedImage image = change.getPageByImage(index);
        ImageIO.write(image, "JPEG", response.getOutputStream());
		/*PrintWriter out = response.getWriter();
		out.println("<html>");
		out.println("<body>username</body></html>");
		out.println("123");
		out.flush();*/
	}

}
